<?php

//// DB Connection & Config
DEFINE('DB_USER', 'ph_kr');
DEFINE('DB_PASSWORD', 'napoleon');
DEFINE('DB_HOST', 'localhost');
DEFINE('DB_NAME', 'whiff_db');

if (!($dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME))) {
    trigger_error('Could not connect to MySQL: ' . mysqli_connect_error());
}

//// DB Query
$Q_AUserAType_AUserAPass =
    "SELECT CU.AdminUserId, CU.UserType
    FROM ControlUsers AS CU
    WHERE CU.AdminUserId='%s' AND CU.AdminPassw=MD5('%s')";

//// DB Query
$Q_ALL_Member =
    "SELECT *
    FROM Membership AS M
    WHERE M.MemberId='%s'";

//// DB Query
$Q_ALL_Email =
    "SELECT *
    FROM Membership AS M
    WHERE M.Email='%s'";

//// DB Query
$I_ALL_Membership =
    "INSERT INTO Membership
        (MemberId, Password, FirstName, LastName, HomePhone, OfficePhone, CellPhone, Email, Paid, Profession, Education, Family, Associations, Interests, CreatedDate, Status) VALUES
	('%s', MD5('%s'), '%s', '%s', %s, %s, %s, '%s', %s, '%s', '%s', '%s', '%s', '%s', '%s', '%s')";

//// DB Query
$Q_UserNameLnameEmailCellHomeOfficeStat_Ordering =
    "SELECT  M.MemberId, M.FirstName, M.LastName, M.Email, M.CellPhone, M.HomePhone, M.OfficePhone, M.Status
    FROM Membership AS M
    ORDER BY %s";

// Update Member Table when Password has NOT changed
$U_None_User_NOPassw =
   "UPDATE Membership AS M
    SET M.MemberId='%s', M.FirstName='%s', M.LastName='%s', 
	M.HomePhone=%s, M.OfficePhone=%s, M.CellPhone=%s, 
	M.Email='%s', M.Profession='%s', M.Education='%s', 
	M.Family='%s', M.Associations='%s',  M.Interests='%s', M.Status='%s'
    WHERE M.MemberId='%s'
    LIMIT 1";

// Update Member Table when Password has changed
$U_None_User_Passw =
   "UPDATE Membership AS M
    SET M.MemberId='%s', M.Password=MD5('%s'), M.FirstName='%s', M.LastName='%s',
	M.HomePhone=%s, M.OfficePhone=%s, M.CellPhone=%s,
	M.Email='%s', M.Profession='%s', M.Education='%s',
	M.Family='%s', M.Associations='%s',  M.Interests='%s', M.Status='%s'
    WHERE M.MemberId='%s'
    LIMIT 1";

//// DB Insert Event
$I_ALL_Events =
    "INSERT INTO Events
        (Date, Title, SpeakerName, SpeakerInfo, Time, VenueName, VenueInfo, Type, Status, FeeMember, FeeGuest, Description) VALUES
	('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %s, %s, '%s')";

//// DB Edit Event
$Q_TitleSpeakerDateTypeStatus_StartdateEnddateOrdering =
    "SELECT  E.EventId, E.Title, E.SpeakerName, E.Date, E.Type, E.Status
    FROM Events AS E
    WHERE E.Date > '%s' AND E.Date < '%s'
    ORDER BY %s";

//// DB Query All Events
$Q_ALL_Event =
    "SELECT *
    FROM Events AS E
    WHERE E.EventId=%s";

// Update Member Table when Password has changed
$U_None_None_EventStatus =
   "UPDATE Events AS E
    SET E.Status='N'
    WHERE E.Status='B' OR  E.Status='U' or E.Status='b' OR  E.Status='u' ";


//// DB Insert Event
$U_ALL_Eventid =
   "UPDATE Events AS E
    SET E.Date='%s', E.Title='%s', E.SpeakerName='%s', E.SpeakerInfo='%s',
    E.Time='%s', E.VenueName='%s', E.VenueInfo='%s', E.Type='%s', E.Status='%s',
    E.FeeMember=%s, E.FeeGuest=%s, E.Description='%s'
    WHERE E.EventId=%s
    LIMIT 1";


//// DB Query Payment Members
$Q_EmailFnameLnameCellHomeOfficeStatPaid_Ordering =
    "SELECT  M.FirstName, M.LastName, M.Email, M.CellPhone, M.HomePhone, M.OfficePhone, M.Status, M.Paid
    FROM Membership AS M
    ORDER BY %s";

//// DB Update Payment to Paid
$U_Paid_Email_PMT =
   "UPDATE Membership AS M
    SET M.Paid=1
    WHERE M.Email='%s'
    LIMIT 1";

//// DB Update Payment to UNPaid
$U_UNPaid_Email_PMT =
   "UPDATE Membership AS M
    SET M.Paid=0
    WHERE M.Email='%s'
    LIMIT 1";

//// DB Reset Payment for All Members
$U_ResetPMT_Membership =
   "UPDATE Membership AS M
    SET M.Paid=0";

?>